﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Syntezator_mowy.Extras
{
    public class SynchrBuffer<T>
    {
        private Queue<T> bufor;
        private object locker;

        public SynchrBuffer()
        {
            this.bufor = new Queue<T>();
            this.locker = new object();
        }

        public void dodaj(T item)
        {
            lock (this.locker)
            {
                this.bufor.Enqueue(item);
            }
        }

        public T wyciagnij()
        {
            lock (this.locker)
            {
                if (this.bufor.Count > 0)
                    return this.bufor.Dequeue();
                else
                    return default(T);
            }
        }

        public int zwrocIlosc()
        {
            return this.bufor.Count;
        }
    }
}
